package engine;

import quadTree.BoundingBox;

public class Force {
	
	/*
	 * @invariant range>=0;
	 */
	private /*@ spec_public @*/ Vector pos;
	private /*@ spec_public @*/ float range;
	private /*@ spec_public @*/ Vector dir;
	/**
	 * Force Constructor
	 * @param position the position this force originates from
	 * @param direction the direction of the force, anything beyond a unit vector is used to represent magnitude
	 * @param range the radius of the force's effects
	 */
	public Force(Vector position, Vector direction, float range)
	{
		if(position==null){System.out.println("Illegal Input, cannot have null position");return;}
		if(range<0){System.out.println("Illegal Input, cannot have negative Force Range");return;}
		this.pos = position;
		this.dir = direction;
		this.range = range;
	}
	/**
	 * getDir returns the 2-D vector representing the direction of the force
	 * @return the direction of the force
	 */
	/*
	 * @ assignable \nothing;
	 * @ returns dir;
	 */
	public Vector getDir() {
		return dir;
	}
	/**
	 * setDir sets the direction of the force
	 * @param dir the direction the force will have
	 */
	/*
	 * @ requires dir!=null;
	 * @ assignable this.dir;
	 * @ ensures this.dir==dir;
	 */
	public void setDir(Vector dir) {
		if(dir==null){System.out.println("Illegal Input, cannot have null Direction");return;}
		this.dir = dir;
	}
	/**
	 * setRange sets the range of the force
	 * @param r the new range of the force
	 */
	/*
	 * @ requires r >=0;
	 * @ assignable range;
	 * @ ensures range == r;
	 */
	void setRange(float r)
	{
		if(r<0){System.out.println("Illegal Input, cannot have negative Force Range");return;}
		range = r;
	}
	/**
	 * setPos sets the position of the force
	 * @param v the new psotion for the force
	 */
	/*
	 * @ requires v!=null;
	 * @ assignable pos;
	 * @ ensures pos = v;
	 */
	public void setPos(Vector v)
	{
		if(v==null){System.out.println("Illegal Input, cannot have Null Position");return;}
		pos = v;
	}
	/**
	 * getPos gets position of the force's epicenter 
	 * @return the force's location
	 */
	/*
	 * @ assignable \nothing;
	 * @ returns pos;
	 * @ensures \result == pos;
	 */
	public Vector getPos()
	{
		return pos;
	}
	/**
	 * getRange returns the range of the force
	 * @return the force's range
	 */
	/*
	 * @ returns range
	 * @ assignable \nothing 
	 */
	public Float getRange()
	{
		return range;	
	}
	/**
	 * Returns a String representation of the Force
	 */
	/*
	 * @ returns new String;
	 * @ assignable \nothing;
	 */
	public String toString()
	{
		return "Force of Range "+range+" at "+pos+" with direction "+dir+"\n";
	}
	/**
	 * getForceBox returns a reference the bounding box of the force
	 * @return bounding box of the force
	 */
	/*
	 * @requires pos!=null;
	 * @assignable \nothing;
	 * @returns new BoundingBox;
	 */
public BoundingBox getForceBox(){
		Vector UL = new Vector(pos.getX()-range, pos.getY()-range);
		Vector LR = new Vector(pos.getX()+range, pos.getY()+range);
		return new BoundingBox(UL, LR);
	}
}
